package com.xingjiejian.feature.function;

import java.util.Arrays;
import java.util.List;

/**
 * 方法引用示例
 * @author XingJiejian
 * @date 2019/5/7 0007
 */
public class TestMethodReferences {
    public static void main(String[] args) {
        //构造器引用：它的语法是Class::new，或者更一般的Class< T >::new
        final Car car = Car.create( Car::new );
        final List< Car > cars = Arrays.asList( car );

        //静态方法引用：它的语法是Class::static_method
        cars.forEach( Car::collide );

        //特定类的任意对象的方法引用：它的语法是Class::method
        cars.forEach( Car::repair );

        //特定对象的方法引用：它的语法是instance::method
        final Car police = Car.create( Car::new );
        cars.forEach( police::follow );
    }
}
